package com.hsmpay.mobile.action.user;

import com.hsmpay.common.pojo.user.User;
import com.hsmpay.common.util.DateConvertUtil;
import com.hsmpay.common.util.URLDecoderTools;
import com.hsmpay.common.util.system.Constant;
import com.hsmpay.mobile.action.base.MobileBaseAction;
import com.hsmpay.mobile.pojo.trans.cardcer.CardCer;
import com.hsmpay.mobile.pojo.user.UserDPI;
import com.hsmpay.mobile.service.trans.cardcer.CardCerService;
import com.hsmpay.mobile.service.user.UserDPIService;
import com.hsmpay.mobile.util.ImgFileUpload;

import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;

/**
 * 手机端用户实名认证 action
 *
 * @author 颜铃璋
 * @date 2013-2-25
 */
@Controller("userDPIAction")
@Scope("prototype")
public class UserDPIAction extends MobileBaseAction {
    private static final long serialVersionUID = 7720826436008178912L;
    private  Logger log = LoggerFactory.getLogger(this.getClass());

    private String identityCard;//身份证
    private String userName;//真实姓名
    private File idPositive;//身份证正面
    private String idPositiveFileName;//上传文件名称
    @SuppressWarnings("unused")
    protected String idPositiveContentType;    //上传文件类型
    private File idBack;//身份证背面
    private String idBackFileName;//上传文件名称
    @SuppressWarnings("unused")
    protected String idBackContentType;    //上传文件类型
    private File head;//身份证背面
    private File cusHoldCardFrontFile; //手持银行卡正面照
    private File cusBizLisenceFile; //企业开户许可证
    @SuppressWarnings("unused")
    private String headFileName;//上传文件名称
    @SuppressWarnings("unused")
    protected String headContentType;    //上传文件类型

    @Resource(name = "userDPIService")
    private UserDPIService<UserDPI, Long> userDPIService;
    @Resource(name = "cardCerService")
    private CardCerService<CardCer, Long> cardCerService;

    private String fc_des3_key;

    /**
     * 用户实名认证
     *
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    public String userDPI() throws Exception {
        log.debug("--- userDPI() start ---");
        terminalTypeId = Long.parseLong(getJsonString("terminalTypeId"));
        roleId = Long.parseLong(getJsonString("roleId"));
        userId = Long.parseLong(getJsonString("userId"));
        identityCard = getJsonString("identityCard");
        userName = getJsonString("userName");

        String idPositiveStr = getJsonString("idPositive");
        if (StringUtils.isNotEmpty(idPositiveStr)) {
            String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
            System.out.println("relPath:"+relPath);
            idPositive = ImgFileUpload.getPicByBase64Str(relPath, idPositiveStr);
        }
        String idBackStr = getJsonString("idBack");
        if (StringUtils.isNotEmpty(idBackStr)) {
            String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
            idBack = ImgFileUpload.getPicByBase64Str(relPath, idBackStr);
        }
        String headStr = getJsonString("head");
        if (StringUtils.isNotEmpty(headStr)) {
            String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
            head = ImgFileUpload.getPicByBase64Str(relPath, headStr);
        }

        log.debug("userId = " + userId);
        log.debug("identityCard = " + identityCard);
        log.debug("userName = " + userName);
        log.debug("idPositiveFileName = " + idPositiveFileName);
        log.debug("idBackFileName = " + idBackFileName);
        if (null == userId) {
            log.warn("用户实名认证时, 传入参数userId为空");
            sendAppErrorMsg("6001", "userId");
            return null;
        }
        if (StringUtils.isBlank(identityCard)) {
            log.warn("用户实名认证时, 传入参数identityCard为空");
            sendAppErrorMsg("6001", "identityCard");
            return null;
        }
        if (StringUtils.isBlank(userName)) {
            log.warn("用户实名认证时, 传入参数userName为空");
            sendAppErrorMsg("6001", "userName");
            return null;
        }
        if (null == idPositive) {
            log.warn("用户实名认证时, 传入参数idPositive为空");
            sendAppErrorMsg("6001", "idPositive");
            return null;
        }
        if (null == idBack) {
            log.warn("用户实名认证时, 传入参数idBack为空");
            sendAppErrorMsg("6001", "idBack");
            return null;
        }
        if (null == head) {
            log.warn("用户实名认证时, 传入参数head为空");
            //sendAppErrorMsg("6001", "head");
            String message = encryptAppMsg(0, "LS02", "尊敬的用户您好，应用版本已更新，请更新软件后再做实名认证！");
            sendAppMsg(message);
            return null;
        }
        try {
            Map<String, Object> res = insertDPI();
            boolean status = (Boolean) res.get("status");
            Map<String, Object> result = null;
            if (!status) {
            	String reqCode = String.valueOf(res.get("reqCode"));
            	sendAppErrorMsg(reqCode);
                return null;
            } else {
                result = (Map<String, Object>) res.get("result");
            }
            sendAppMsg(result);

            //删除
            //deleteErrorDPI();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            log.debug("--- userDPI() end ---");
            idPositive.delete();
            idBack.delete();
            head.delete();

            idPositive = null;
            idBack = null;
            head = null;
        }
        return null;
    }
    /**
     * 公众号 实名认证接口
     * @return
     * @throws Exception
     */
    public String customerRegisterSaveCusImg() throws Exception {
    	log.debug("--- userDPI() start ---");
    	clientType = 1; 
        roleId = 2l;
        
        String user = getRequest().getParameter("userId");
        if(StringUtils.isNotEmpty(user)){
        	userId = Long.parseLong(user);
        }
    
    	identityCard = getRequest().getParameter("cusIDNo");//身份证
    	userName = getRequest().getParameter("cusLgPson");//姓名
    	String cusSettleAccNo = getRequest().getParameter("cusSettleAccNo");//银行卡号
    	
    	String cusIDFront = getRequest().getParameter("cusIDFront");//身份证正面照
    	String cusIDBack = getRequest().getParameter("cusIDBack");//身份证背面照
    	String cusHoldIDFront = getRequest().getParameter("cusHoldIDFront");//手持身份证正面照
    	String cusHoldCardFront = getRequest().getParameter("cusHoldCardFront");//手持银行卡正面照
    	String cusBizLisence = getRequest().getParameter("cusBizLisence");// 企业开户许可证
        terminalTypeId = Long.valueOf(getRequest().getParameter("terminalTypeId"));//
        
    	log.debug("userId = " + userId);
    	log.debug("identityCard = " + identityCard);
    	log.debug("userName = " + userName);
    	log.debug("idPositiveFileName = " + idPositiveFileName);
    	log.debug("idBackFileName = " + idBackFileName);
    	if (null == terminalTypeId) {
    		log.warn("用户实名认证时, 传入参数terminalTypeId为空");
    		sendWeChatErrorMsg("6001", "terminalTypeId");
    		return null;
    	}
    	
    	
    	String idPositiveStr = cusIDFront;
    	if (StringUtils.isNotEmpty(idPositiveStr)) {
    		String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
    		log.info("relPath:"+relPath);
    		idPositive = ImgFileUpload.getPicByBase64Str(relPath, idPositiveStr);
    	}
    	String idBackStr = cusIDBack;
    	if (StringUtils.isNotEmpty(idBackStr)) {
    		String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
    		idBack = ImgFileUpload.getPicByBase64Str(relPath, idBackStr);
    	}
    	String headStr = cusHoldIDFront;
    	if (StringUtils.isNotEmpty(headStr)) {
    		String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
    		head = ImgFileUpload.getPicByBase64Str(relPath, headStr);
    	}
    	
    	String cusHoldCardFrontStr = cusHoldCardFront;
    	if (StringUtils.isNotEmpty(cusHoldCardFrontStr)) {
    		String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
    		cusHoldCardFrontFile = ImgFileUpload.getPicByBase64Str(relPath, cusHoldCardFrontStr);
    	}
    	String cusBizLisenceStr = cusBizLisence;
    	if (StringUtils.isNotEmpty(cusBizLisenceStr)) {
    		String relPath = getRealPath("/images") +File.separator+"images"+ File.separator + "temp" + File.separator + DateConvertUtil.dateString(new Date(), "yyyyMMddhhmmssSSS") + ".jpg";
    		cusBizLisenceFile = ImgFileUpload.getPicByBase64Str(relPath, cusBizLisenceStr);
    	}
    	if (null == userId) {
    		log.warn("用户实名认证时, 传入参数userId为空");
    		sendWeChatErrorMsg("6001", "userId");
    		return null;
    	}
    	if (null == cusSettleAccNo) {
    		log.warn("用户实名认证时, 传入参数userId为空");
    		sendWeChatErrorMsg("6001", "cusSettleAccNo");
    		return null;
    	}
    	if (StringUtils.isBlank(identityCard)) {
    		log.warn("用户实名认证时, 传入参数identityCard为空");
    		sendWeChatErrorMsg("6001", "identityCard");
    		return null;
    	}
    	if (StringUtils.isBlank(userName)) {
    		log.warn("用户实名认证时, 传入参数userName为空");
    		sendWeChatErrorMsg("6001", "userName");
    		return null;
    	}
    	if (null == idPositive) {
    		log.warn("用户实名认证时, 传入参数idPositive为空");
    		sendWeChatErrorMsg("6001", "idPositive");
    		return null;
    	}
    	if (null == idBack) {
    		log.warn("用户实名认证时, 传入参数idBack为空");
    		sendWeChatErrorMsg("6001", "idBack");
    		return null;
    	}
    	if (null == head) {
    		log.warn("用户实名认证时, 传入参数head为空");
    		//sendAppErrorMsg("6001", "head");
    		String message = encryptAppMsg(0, "LS02", "尊敬的用户您好，应用版本已更新，请更新软件后再做实名认证！");
    		sendWeChatErrorMsg(message);
    		return null;
    	}
    
    	
    	 JSONObject result = new JSONObject();
    	try {
    		//TODO 判断是否存在
    		Map<String, Object> res = insertDPI();
    		uploadCardCerd(userId, cusSettleAccNo, idPositive, idBack, head, cusHoldCardFrontFile!=null?cusHoldCardFrontFile:cusBizLisenceFile);
    		
    		boolean status = (Boolean) res.get("status");
    		
		    result.put("code", "0");
		    result.put("msg", "上传图片成功!");
		    sendWeChatMsg(result.toString());
        
    		log.info("上传实名认证图片成功{}:{}",new Object[]{userId,userName});
    		//删除
    		//deleteErrorDPI();
    	} catch (Exception e) {
		    result.put("code", "1");
		    result.put("msg", "上传图片失败!");
		    sendWeChatMsg(result.toString());
    		e.printStackTrace();
    	} finally {
    		log.debug("--- userDPI() end ---");
    		idPositive.delete();
    		idBack.delete();
    		head.delete();
    		
    		idPositive = null;
    		idBack = null;
    		head = null;
    	}
    	return null;
    }
    
    
    /**
     * 上传银行卡认证
     * @return
     * @throws Exception
     */
    public String uploadCardCerd(Long userId,String bankCard,File idPositive,File idBack,File head,File cardPositive) throws Exception {
        	
    	    CardCer cardCer = new CardCer();
            cardCer.setVerifiType(1);//提现
            String dPIUrl = Constant.getAttribute("SERVER_CARDCER_URL");
            StringBuilder sb = new StringBuilder();
            String dirDateStr = DateConvertUtil.dateString(new Date());
            String baseRPath = ImgFileUpload.mkDirectory(sb.append(getRealPath(dPIUrl)).append(File.separator).append(dirDateStr).toString());
            String fileType = ".jpg";//ImgFileUpload.getFileType(idPositiveFileName);
            String dateStr = "";
            String filePath = "";
            String idPositiveUrl = "";

            //证件正面
            if (null != idPositive) {
                log.debug("上传身份证证件正面");
                dateStr = DateConvertUtil.dateString(new Date(), "hhmmssSSS");
                sb = new StringBuilder();
                filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
                sb = new StringBuilder();
                idPositiveUrl = sb.append(dPIUrl).append(dirDateStr).append("/").append(dateStr).append(fileType).toString();
                ImgFileUpload.uploadAndThumd(filePath, idPositive, 80, 80, terminalTypeId);
                cardCer.setIdPositivePath(idPositiveUrl);//证件正面
            }
            //证件背面
            if (null != idBack) {
                log.debug("上传身份证证件背面");
                dateStr = DateConvertUtil.dateString(new Date(), "hhmmssSSS");
                sb = new StringBuilder();
                filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
                sb = new StringBuilder();
                String idBackUrl = sb.append(dPIUrl).append(dirDateStr).append("/").append(dateStr).append(fileType).toString();
                ImgFileUpload.uploadAndThumd(filePath, idBack, 80, 80, terminalTypeId);
                cardCer.setIdBackPath(idBackUrl);//证件背面
            }
            //头像
            if (null != head) {
                log.debug("上传卡号头像");
                dateStr = DateConvertUtil.dateString(new Date(), "hhmmssSSS");
                sb = new StringBuilder();
                filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
                sb = new StringBuilder();
                String headUrl = sb.append(dPIUrl).append(dirDateStr).append("/").append(dateStr).append(fileType).toString();
                ImgFileUpload.uploadAndThumd(filePath, head, 80, 80, terminalTypeId);
                cardCer.setHeadPath(headUrl);//头像
            }
            
            
            
            //卡号正面
            if (null != cardPositive) {
                log.debug("上传卡号正面");
                dateStr = DateConvertUtil.dateString(new Date(), "hhmmssSSS");
                sb = new StringBuilder();
                filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
                sb = new StringBuilder();
                String cardPositiveUrl = sb.append(dPIUrl).append(dirDateStr).append("/").append(dateStr).append(fileType).toString();
                ImgFileUpload.uploadAndThumd(filePath, cardPositive, 80, 80, terminalTypeId);
                cardCer.setCardPositivePath(cardPositiveUrl);//卡号正面
            }
            
			cardCer.setStatus(2);// 未审核
			cardCer.setCreateDate(new Date());
			cardCer.setUserId(userId);
			cardCer.setVerifiType(1);// 提现审核
			cardCer.setBankCard(bankCard);
			cardCerService.insertOrUpdateCardCer(cardCer);
       
        return null;
    }
    

    public void deleteErrorDPI() {
        try {
            log.debug("--- userDPI() end ---");
            UserDPI parm = new UserDPI();
            parm.setUserId(userId);
            //parm.setTerminalTypeId(terminalTypeId);
            //parm.setRoleId(roleId);
            //parm.setIdcard(identityCard);
            parm.setStatus(0);
            //parm.setOtherParam(" D.STATUS <> 0");
            List<UserDPI> userDPIList = userDPIService.searchEntityList(parm);

            for (UserDPI dpi : userDPIList) {
                idPositive = new File(getRealPath(dpi.getPositivePath()));
                idBack = new File(getRealPath(dpi.getBackPath()));

                userDPIService.deleteEntity(dpi);
                idPositive.delete();
                idBack.delete();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            log.debug("--- userDPI() end ---");
        }
    }

    public Map<String, Object> insertDPI() throws Exception {
        try {
            Map<String, Object> res = new HashMap<String, Object>();

            User user = userService.getUserById(userId);
            userName = URLDecoderTools.decodeUTF8(userName).trim();
            user.setUserName(userName);
            user.setCardholder(userName);
            user.setIdentityCard(identityCard);
            //图片压缩类
            //CompressPic mypic = new CompressPic();

            String dPIUrl = Constant.getAttribute("SERVER_DPI_URL");
            StringBuilder sb = new StringBuilder();
            String dirDate = DateConvertUtil.dateString(new Date(), "yyyy-MM-dd");
            String baseRPath = ImgFileUpload.mkDirectory(sb.append(getRealPath(dPIUrl)).append(dirDate).append(File.separator).append(userId).toString());

            //正面
            Date date = new Date();
            String dateStr = DateConvertUtil.dateString(date, "yyyyMMddhhmmssSSS");
            String fileType = ".jpg";//ImgFileUpload.getFileType(idPositiveFileName);
            sb = new StringBuilder();
            String filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
            sb = new StringBuilder();
            String idPositiveUrl = sb.append(dPIUrl).append(dirDate).append("/").append(userId).append("/").append(dateStr).append(fileType).toString();
            ImgFileUpload.uploadAndThumd(filePath, idPositive, 80, 80, terminalTypeId);

            //缩略图
            /*sb = new StringBuilder();
			String baseRThumbPath = FileUpload.mkDirectory(sb.append(baseRPath).append(File.separator).append("thumb").toString());
			sb = new StringBuilder();
			String thumbName = sb.append(dateStr).append(fileType).toString();
			mypic.compressPic(baseRPath+"/", baseRThumbPath + "/", thumbName, thumbName, 80, 80, false);*/

            //反面
            date = new Date();
            dateStr = DateConvertUtil.dateString(date, "yyyyMMddhhmmssSSS");
            fileType = ".jpg";//ImgFileUpload.getFileType(idBackFileName);
            sb = new StringBuilder();
            filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
            sb = new StringBuilder();
            String idBackUrl = sb.append(dPIUrl).append(dirDate).append("/").append(userId).append("/").append(dateStr).append(fileType).toString();
            ImgFileUpload.uploadAndThumd(filePath, idBack, 80, 80, terminalTypeId);

            //头像
            date = new Date();
            dateStr = DateConvertUtil.dateString(date, "yyyyMMddhhmmssSSS");
            sb = new StringBuilder();
            filePath = sb.append(baseRPath).append(File.separator).append(dateStr).append(fileType).toString();
            sb = new StringBuilder();
            String headUrl = sb.append(dPIUrl).append(dirDate).append("/").append(userId).append("/").append(dateStr).append(fileType).toString();
            ImgFileUpload.uploadAndThumd(filePath, head, 80, 80, terminalTypeId);
            

            //缩略图
			/*sb = new StringBuilder();
			thumbName = sb.append(dateStr).append(fileType).toString();
			mypic.compressPic(baseRPath+"/", baseRThumbPath + "/", thumbName, thumbName, 80, 80, false);*/

            UserDPI userDPI = new UserDPI();
            userDPI.setUserId(userId);
            userDPI.setIdcard(identityCard);
            userDPI.setCardType(1);
            userDPI.setStatus(2);//0:认证失败 1:认证通过 2:审核中 3:未申请认证 默认2
            userDPI.setPositivePath(idPositiveUrl);
            userDPI.setBackPath(idBackUrl);
            userDPI.setHeadPath(headUrl);//头像
            userDPI.setCardholder(userName);//添加姓名
            userDPIService.userDPI(userDPI, user);

            Map<String, Object> result = new LinkedHashMap<String, Object>();
            result.put("reqCode", "0000");
            result.put("reqMsg", "实名认证提交成功！");
            result.put("status", 2);
            res.put("result", result);
            res.put("status", true);
            return res;
        } catch (Exception e) {
            throw e;
        } finally {
            log.debug("--- userDPI() end ---");
        }
    }

    /**
     * 表单提交
     *
     * @return
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    public String plaintextUserDPI() throws Exception {
        log.debug("--- plaintextUserDPI() start ---");
//		JSONObject js = JSONObject.fromObject(getRequest().getAttribute(FC_DATA));
//		String fc_des3_key = (String) getRequest().getAttribute(FC_DES3_Key);
//		terminalTypeId = Long.parseLong(js.getString("terminalTypeId"));
//		roleId = Long.parseLong(js.getString("roleId"));
//		
//		
//		if(js.containsKey("userId"))
//			userId = Long.parseLong(js.getString("userId"));
//		if(js.containsKey("identityCard"))
//			identityCard = js.getString("identityCard");
//		if(js.containsKey("userName"))
//			userName = js.getString("userName");
//		if(js.containsKey("idPositive")){
//			String idPositiveStr = js.getString("idPositive");
//			String relPath = getRealPath("/images")+File.separator+"temp"+File.separator+DateConvertUtil.dateString(new Date(),"yyyyMMddhhmmssSSS")+".jpg";
//			idPositive = ImgFileUpload.getPicByBase64Str(relPath,idPositiveStr);
//		}
//		if(js.containsKey("idBack")){
//			String idBackStr = js.getString("idBack");
//			String relPath = getRealPath("/images")+File.separator+"temp"+File.separator+DateConvertUtil.dateString(new Date(),"yyyyMMddhhmmssSSS")+".jpg";
//			idBack = ImgFileUpload.getPicByBase64Str(relPath,idBackStr);
//		}	

        log.debug("terminalTypeId = " + terminalTypeId);
        log.debug("roleId = " + roleId);
        log.debug("userId = " + userId);
        log.debug("identityCard = " + identityCard);
        log.debug("userName = " + userName);
        log.debug("idPositiveFileName = " + idPositiveFileName);
        log.debug("idBackFileName = " + idBackFileName);
        if (null == userId) {
            log.warn("用户实名认证时, 传入参数userId为空");
            sendAppErrorMsg("6001", "userId");
            return null;
        }
        if (StringUtils.isBlank(identityCard)) {
            log.warn("用户实名认证时, 传入参数identityCard为空");
            sendAppErrorMsg("6001", "identityCard");
            return null;
        }
        if (StringUtils.isBlank(userName)) {
            log.warn("用户实名认证时, 传入参数userName为空");
            sendAppErrorMsg("6001", "userName");
            return null;
        }
        if (null == idPositive) {
            log.warn("用户实名认证时, 传入参数idPositive为空");
            sendAppErrorMsg("6001", "idPositive");
            return null;
        }
        if (null == idBack) {
            log.warn("用户实名认证时, 传入参数idBack为空");
            sendAppErrorMsg("6001", "idBack");
            return null;
        }
        if (StringUtils.isBlank(fc_des3_key)) {
            log.warn("用户实名认证时, 传入参数fc_des3_key为空");
            sendAppErrorMsg("6001", "fc_des3_key");
            return null;
        }
        if (null == head) {
            log.warn("用户实名认证时, 传入参数head为空");
            //sendAppErrorMsg("6001", "head");
            String message = encryptAppMsg(0, "LS02", "尊敬的用户您好，应用版本已更新，请更新软件后再做实名认证！");
            sendAppMsg(message);
            return null;
        }
        try {
            Map<String, Object> res = insertDPI();
            
            boolean status = (Boolean) res.get("status");
            Map<String, Object> result = null;
            if (!status) {
            	String reqCode = String.valueOf(res.get("reqCode"));
            	sendAppErrorMsg(reqCode);
                return null;
            } else {
                result = (Map<String, Object>) res.get("result");
            }
            sendAppMsg(result, fc_des3_key);
            //this.sendAjaxResponse(result);
            //删除
            //deleteErrorDPI();
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            log.debug("--- plaintextUserDPI() end ---");
            idPositive.delete();
            idBack.delete();
            head.delete();

            idPositive = null;
            idBack = null;
            head = null;
        }
        return null;
    }

    /**
     * 获得实名认证  状态
     *
     * @return
     * @throws Exception
     */
    public String getDPIStatus() throws Exception {
        log.debug("--- userDPI() start ---");
        JSONObject js = JSONObject.fromObject(getRequest().getAttribute(FC_DATA));
        String fc_des3_key = (String) getRequest().getAttribute(FC_DES3_Key);
        terminalTypeId = Long.parseLong(js.getString("terminalTypeId"));
        roleId = Long.parseLong(js.getString("roleId"));
        if (js.containsKey("userId"))
            userId = Long.parseLong(js.getString("userId"));

        log.debug("terminalTypeId = " + terminalTypeId);
        log.debug("roleId = " + roleId);
        log.debug("userId = " + userId);
        if (null == userId) {
            log.warn("用户实名认证时, 传入参数userId为空");
            sendAppErrorMsg("6001", "userId");
            return null;
        }
        try {
            log.debug("--- getDPIStatus() start ---");
            UserDPI userDPI = new UserDPI();
            userDPI.setUserId(userId);
            userDPI.setIsHistory(0);
            userDPI = userDPIService.searchEntity(userDPI);

            Map<String, Object> result = new LinkedHashMap<String, Object>();
            result.put("reqCode", "0000");
            result.put("reqMsg", "查询实名认证请求成功！");
            result.put("status", (null == userDPI.getStatus() || 4 == userDPI.getStatus().intValue()) ? 3 : userDPI.getStatus());//4重置暂时改为3
            result.put("dPIErrorMsg", null == userDPI.getDescription() ? "" : userDPI.getDescription());
            sendAppMsg(result, fc_des3_key);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            log.debug("--- getDPIStatus() end ---");
        }
        return null;
    }


    //---------------------set get start--------------------
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public void setIdentityCard(String identityCard) {
        this.identityCard = identityCard;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setIdPositive(File idPositive) {
        this.idPositive = idPositive;
    }

    public void setIdPositiveFileName(String idPositiveFileName) {
        this.idPositiveFileName = idPositiveFileName;
    }

    public void setIdPositiveContentType(String idPositiveContentType) {
        this.idPositiveContentType = idPositiveContentType;
    }

    public void setIdBack(File idBack) {
        this.idBack = idBack;
    }

    public void setIdBackFileName(String idBackFileName) {
        this.idBackFileName = idBackFileName;
    }

    public void setIdBackContentType(String idBackContentType) {
        this.idBackContentType = idBackContentType;
    }
    //---------------------set get end--------------------

    public void setFc_des3_key(String fc_des3_key) {
        this.fc_des3_key = fc_des3_key;
    }

    public void setTerminalTypeId(Long terminalTypeId) {
        this.terminalTypeId = terminalTypeId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public void setHead(File head) {
        this.head = head;
    }

    public void setHeadFileName(String headFileName) {
        this.headFileName = headFileName;
    }

    public void setHeadContentType(String headContentType) {
        this.headContentType = headContentType;
    }
	public File getCusHoldCardFrontFile() {
		return cusHoldCardFrontFile;
	}
	public void setCusHoldCardFrontFile(File cusHoldCardFrontFile) {
		this.cusHoldCardFrontFile = cusHoldCardFrontFile;
	}
	public File getCusBizLisenceFile() {
		return cusBizLisenceFile;
	}
	public void setCusBizLisenceFile(File cusBizLisenceFile) {
		this.cusBizLisenceFile = cusBizLisenceFile;
	}
}
